﻿using Cl.Model.DataBaseEntityDtos.User.RegisterUsers;
using Cl.Model.DataBaseEntityDtos.User.UserLogins;
using Cl.Model.Results;
using Cl.Service.Service.User;
using Cl.Service.Service.User.UserLogins;
using Cl.Utils;
using Cl.WebApi.Controllers;
using Cl.WebApi.SwaggerModel;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Cl.WebApi.Areas.Admin.Users
{
    /// <summary>
    /// 登录管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiExplorerSettings(GroupName = Grouping.ClientGroup)]
    public class UserLoginController : BaseController
    {
        #region 构造函数

        private IUserLoginService _userLoginService;


        /// <summary>
        /// 构造函数
        /// </summary>
        public UserLoginController(IUserLoginService userLoginService)
        {
            _userLoginService = userLoginService;
        }

        #endregion

        /// <summary>
        /// 注册用户
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [AllowAnonymous]
        [HttpPost]
        public ResultInfoModel RegisterUser(RegisterUserInputDto obj)
        {
            var result = _userLoginService.RegisterUser(obj);
            return result;
        }

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [AllowAnonymous]
        [HttpPost]
        public ResultInfoModel Login(LoginRequest request)
        {
            var result = _userLoginService.Login(request);
            return result;
        }

        /// <summary>
        /// 登出
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ResultInfoModel Logout()
        {
            var result = _userLoginService.Logout(GlobalUserManager.Account);
            return result;
        }
    }
}
